Skip to content

Add new rules for brotli, socket and ip#59

Merged
nunoplopes merged 18 commits into
Cpp2Rust:masterfrom
lucic71:rules
May 11, 2026
Merged

Add new rules for brotli, socket and ip#59
nunoplopes merged 18 commits into
Cpp2Rust:masterfrom
lucic71:rules

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 3, 2026

This PR adds more translated symbols for brotli (enum values + functions), socket (enums + macros), and ip (enums).

This is not straight forward because symbols like IPPROTO_TCP are defined as enum on Linux and macro on macOS. To handle this, I modified cpp_rule_preprocessor + mapper to match macros and VisitIntegerLiteral to emit the translated macro.

Because on one platform the symbol is an enum and on the other it's a macro, the AST of the translated program is also different. To be able to generate the same code on both platforms, I use IsCastRedundantInRust to normalize (libc::IPPROTO_TCP as i32) (Linux) and libc::IPPROTO_TCP (macOS) to libc::IPPROTO_TCP. This uses the fact that libc::IPPROTO_TCP is already an i32 in Rust, so the cast is redundant.

@lucic71 lucic71 force-pushed the rules branch 4 times, most recently from 5f28bd8 to cd990ac Compare May 10, 2026 20:15
@lucic71 lucic71 marked this pull request as draft May 10, 2026 20:18
@lucic71 lucic71 marked this pull request as ready for review May 11, 2026 09:22
@nunoplopes nunoplopes merged commit dd667fb into Cpp2Rust:master May 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants